﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using GCELibrary.Current;
namespace ZF.BLL.Page
{
    /// <summary>
    /// 消息提示页面基类
    /// </summary>
    public abstract class WarnPage:PageBase,IWarnPage
    {
        public override bool AutoBindPageArgument
        {
            get
            {
                return false;
            }
            set
            {
                base.AutoBindPageArgument = value;
            }
        }

        new string Title = "";
        /// <summary>
        /// 提示图片
        /// </summary>
        public abstract Image Picture { get; }
        /// <summary>
        /// 跳转连接
        /// </summary>
        public abstract HyperLink Link { get; }
        /// <summary>
        /// 提示内容
        /// </summary>
        public abstract Literal Board { get; }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            SetUI();
        }

        protected virtual void SetUI()
        {
            this.Header.Title = Title;

            //消息内容
            object oContent = Request.QueryString["Content"];
            //页面切换模式
            object oLinkType = Request.QueryString["LinkType"];
            //跳转页面
            object oPage = Request.QueryString["Page"];
            //消息类型
            object oExpType = Request.QueryString["ExpType"];


            string msg = oContent != null ? (string)oContent : "出错啦！！！";




            //消息内容
            this.Board.Text = oContent != null ? (string)oContent : "出错啦！！！";


            //页面切换模式
            WarnLink linkType = oLinkType != null ? (WarnLink)System.Enum.Parse(typeof(WarnLink), (string)oLinkType) : WarnLink.GoBack;
            //消息类型
            WarnIcon icon = oExpType != null ? (WarnIcon)System.Enum.Parse(typeof(WarnIcon), (string)oExpType) : WarnIcon.Information;
            this.Picture.ImageUrl = GetIcon(icon);
            string sPage = oPage != null ? (string)oPage : "/default.aspx";
            switch (linkType)
            {
                case WarnLink.Close:
                    //this.Link.Text = "关闭 点击";
                    Link.NavigateUrl = "javascript:window.close()";
                    break;
                case WarnLink.Exit:
                    //this.Link.Text = "转到首页  点击";
                    Link.NavigateUrl = SiteInfo.SystemConfig.SystemDefaultPage;
                    break;
                case WarnLink.GoDefault:
                    //this.Link.Text = "转到首页  点击";
                    Link.NavigateUrl = SiteInfo.SystemConfig.SystemDefaultPage;
                    break;
                case WarnLink.GoBack:
                    //this.Link.Text = "返回  点击";
                    Link.NavigateUrl = "javascript:window.history.go(-1)";
                    break;
                case WarnLink.GoPage:
                    //this.Link.Text = "跳转  点击";
                    Link.NavigateUrl = sPage;
                    break;
                case WarnLink.Current:
                    //this.Link.Text = "返回  点击";
                    Link.NavigateUrl = sPage;
                    break;
                case WarnLink.GoLogin:
                    string url = SiteInfo.SystemConfig.SystemLoginPage;;
 
                    System.Web.HttpContext.Current.Response.Write(string.Format("<script>alert('{1}');top.location='{0}'</script>", url, this.Board.Text));
                    break;
            }
        }

        protected virtual string GetIcon(WarnIcon icon)
        {
            if (icon != WarnIcon.Success)
            {
                return "/images/warn/err.png"; 
            }
            else
            {
                 return "/images/warn/success.png"; 
            }
        }

    }
    /// <summary>
    /// 消息提示页面接口
    /// </summary>
    public interface IWarnPage
    {
        /// <summary>
        /// 提示图片
        /// </summary>
        Image Picture { get; }
        /// <summary>
        /// 跳转连接
        /// </summary>
        HyperLink Link { get; }
        /// <summary>
        /// 提示内容
        /// </summary>
        Literal Board { get; }
    }
}
